/**
 * ElectronServiceImpl.java
 */
package com.prs.crm.service.document.electron.impl;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.document.electron.ElectronDao;
import com.prs.crm.domain.document.electron.Electron;
import com.prs.crm.service.document.electron.ElectronService;
import com.prs.crm.service.impl.BaseServiceImpl;

/**
 * @author ZhuDongMei
 * @E-mail:1223984339@qq.com
 * @qq:1223984339
 * @version 创建时间：2011-3-16 上午11:12:28 简单说明
 */

public class ElectronServiceImpl extends BaseServiceImpl<Electron, ElectronDao> implements
		ElectronService {
	@Override
	public Collection<Electron> convertToElectron(String ids) {
		try{
			Collection<Electron> electrons = new ArrayList<Electron>();
			for(String id : ids.split(",")) {
				Electron electron = new Electron();
				electron.setId(Integer.valueOf(id));
				electrons.add(electron);
			}
			return electrons;
			}catch (NumberFormatException e) {
				e.printStackTrace();
				return null;
				}
	}

	@Override
	public List<Electron> getAllElectrons() {
		// TODO Auto-generated method stub
		return this.getDao().getAllElectrons();
	}

	@Override
	public Electron getElectronById(Serializable id) {
		// TODO Auto-generated method stub
		return this.getDao().getElectronById(id);
	}

	@Override
	public Collection<Electron> getRootElectron() {
		// TODO Auto-generated method stub
		return this.getDao().getRootElectron();
	}

	@Override
	public void saveElectrons(Electron electron, File file, String fileName) {
        Attach cAttach=FileUtil.getInstance().saveFile(file, fileName,"",Constrains.UPLOAD_DIR_ELECTRON);
		
		if(cAttach.getSrc()!=null){
		//	rule.setDocument_file(cAttach.getSrc());
		}
		this.getDao().save(electron);
		
	}

	@Override
	public int removeElectron(Integer id) {
		// TODO Auto-generated method stub
		return this.getDao().removeElectron(id);
	}

}
